/*
 * ExplicaException.java
 *
 * $Id: ExplicaException.java,v 1.1 2008-03-18 12:58:46 mario Exp $ 
 */
package org.ceteca.explica.core;

import org.ceteca.explica.core.util.ResultMessage;

/**
 * This class encapsulates and holds all the errors that might have taken
 * place during any of the application operations.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Encapsulate and pass on the error messages to the upper layers. </ul>
 * </li>
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2007 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class ExplicaException extends Exception {
	private static final long serialVersionUID = 10000009;
	
	/**
	 * ResultMessage instance with the message build as the result of
	 * the operation that raised the exception.
	 */
	private ResultMessage resMsg;

	/**
	 * Default ExplicaException constructor.
	 */
	public ExplicaException() {
		super();
		this.resMsg = null;
	}
	
	/**
	 * ExplicaException constructor with the message to show to the end user.
	 * @param resMsg ResultMessage, operation result message.
	 */
	public ExplicaException(ResultMessage resMsg) {
		super();
		this.resMsg = resMsg;
	}
	
	public String getMessage() {
		if (this.resMsg == null)
			return "Unknown exception!";
		else
			return this.resMsg.getMessage();
	}

	/**
	 * Gets the message taken as the result of the operation that
	 * raised the exception.
	 * @return ResultMessage, operation result message.
	 */
	public ResultMessage getResMsg() {
		return resMsg;
	}
	/**
	 * Sets up the message taken as the result of the operation that
	 * raised the exception.
	 * @param resMsg ResultMessage, operation result message.
	 */
	public void setResMsg(ResultMessage resMsg) {
		this.resMsg = resMsg;
	}

	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: ExplicaException.java,v 1.1 2008-03-18 12:58:46 mario Exp $";
	}
}

